<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="挂号单号" prop="regId">
        <el-input
          v-model="queryParams.regId"
          placeholder="请输入挂号单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="患者姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单号" align="center" prop="orderId" />
      <el-table-column label="挂号单号" align="center" prop="regId" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="总金额" align="center" prop="orderAmount" />
      <el-table-column label="支付类型" align="center" prop="payType" :formatter="statusFormat1"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus" :formatter="statusFormat" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
           
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改岗位对话框 -->
    <el-dialog  :visible.sync="open" append-to-body>
      <el-table v-loading="loading" :data="orderItemList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="详情id" align="center" prop="itemId" />
      <el-table-column label="处方ID" align="center" prop="coId" />
      <el-table-column label="名称" align="center" prop="itemName" />
      <el-table-column label="价格" align="center" prop="itemPrice" />
      <el-table-column label="数量" align="center" prop="itemNum" />
      <el-table-column label="小计" align="center" prop="itemAmount" />
      <el-table-column label="类型" align="center" prop="itemType" :formatter="statusFormat1"/>
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listCommon,itemDetail } from "@/api/order/commit";

export default {
  name: "commit",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      orderList: [],
      orderItemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      statusOptions1: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        regId :undefined,
        patientName:undefined
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
   
    this.getDicts("his_order_details_status").then(response => {
      this.statusOptions = response.data;
    });

      this.getDicts("his_pay_type_status").then(response => {
      this.statusOptions1 = response.data;
    });
    
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listCommon(this.queryParams).then(response => {
       
        this.orderList = response.rows;
        console.log(this.orderList)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 岗位状态字典翻译
    statusFormat(row, column) {
     
      return this.selectDictLabel(this.statusOptions, row.orderStatus);
    },

     // 岗位状态字典翻译
    statusFormat1(row, column) {
     
      return this.selectDictLabel(this.statusOptions1, row.payType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // // 表单重置
    // reset() {
    //   this.form = {
    //     postId: undefined,
    //     postCode: undefined,
    //     postName: undefined,
    //     postSort: 0,
    //     status: "0",
    //     remark: undefined
    //   };
    //   this.resetForm("form");
    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleDetail(row){
        const orderId = row.orderId
        itemDetail(orderId).then(res => {
          this.orderItemList = res.data
          this.open = true
        })
    }

  }
};
</script>